/**
 * PHOSIDE: PHosphorylation Site IDentification Engine.
 * Copyright 2009 Digital Biology Lab, University of Missouri.
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version. <p/> This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more
 * details.
 */

package phoside.io.fasta;

import phoside.io.fasta.parser.PhosphoHeaderRule;
import phoside.io.fasta.parser.DefaultPhosphoHeaderParser;
import java.io.IOException;

import java.util.Set;

import phoside.PhosphoProteins;

/**
 *
 * @author gjj
 */
public class PhosphoReaderFromFastaWithSitesInHeader
                        extends FastaProteinsReaderFromFile {

    public PhosphoReaderFromFastaWithSitesInHeader(final String fasta,
            final PhosphoProteins phosphoData, final PhosphoHeaderRule headerRule)
            throws IOException{
        super(fasta, new PhosphoReaderFastaVisitorWithSitesInHeader(
                phosphoData, headerRule));
    }

}

class PhosphoReaderFastaVisitorWithSitesInHeader extends ProteinsReaderFastaVisitor {
    public PhosphoReaderFastaVisitorWithSitesInHeader(final PhosphoProteins phosphoData,
                                         final PhosphoHeaderRule rule) {
        super(phosphoData, new DefaultPhosphoHeaderParser(rule));
    }

    /**
     *
     * @param header
     * @param sequence
     */
    @Override
    public void visit(final String header, final String sequence) {
        super.visit(header, sequence);
        
        String accession = headerParser.getAccession();
        if (accession != null) {
            Set<Integer> sites = ((DefaultPhosphoHeaderParser)headerParser).getSites();
            if (sites!=null) {
                ((PhosphoProteins)proteins).addSites(accession, sites);
            }
        }
    }

}
